package com.atguigu.lease.web.admin.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.atguigu.lease.model.entity.SystemPost;
import com.atguigu.lease.model.entity.SystemUser;
import com.atguigu.lease.web.admin.mapper.SystemUserMapper;
import com.atguigu.lease.web.admin.service.SystemUserService;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserItemVo;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
/**
 * @author liubo
 * @description 针对表【system_user(员工信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
@RequiredArgsConstructor
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {
    private final SystemUserMapper systemUserMapper;
    @Override
    public IPage<SystemUserItemVo> pageSystemUserItemVo(Page<SystemUserItemVo> page, SystemUserQueryVo queryVo) {
        //systemUserMapper.pageSystemUserItemVo(page,queryVo);
        return systemUserMapper.pageSystemUserItemVo(page,queryVo);
    }

    @Override
    public SystemUserItemVo getSystemUserItemVo(Long id) {

        SystemUser byId = getById(id);
        SystemUserItemVo systemUserItemVo = BeanUtil.copyProperties(byId, SystemUserItemVo.class);
        Long postId = byId.getPostId();
        SystemPost one = Db.lambdaQuery(SystemPost.class)
                .eq(SystemPost::getId, id)
                .one();
        systemUserItemVo.setPostName(one.getName());
        return systemUserItemVo;
    }
}




